#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
	int y, d, t, i, sum=0;
	scanf("%d%d", &y,&d);
	if (y < 1900 || y > 2018 || d < 1 || d > 366)
		return 1;
	if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
		t = 29;
	else t = 28;
	int arr[] = { 31,t,31,30,31,30,31,31,30,31,30,31 };
	for (i = 0; i < 12; i++) {
		if (sum + arr[i] >= d) {
			printf("%d %d", i+1, d - sum);
			return 0;
			}
		sum += arr[i];
	}
	return 0;
}